package jym.tan.movielibrary.component.renderer;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class DateCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 58L;

	public DateCellRenderer() {
		super();
		setOpaque(true);
		setHorizontalAlignment(CENTER);			    
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if (value instanceof Date) {
			String date = new SimpleDateFormat("dd-MM-yyyy").format((Date) value);
			setText(date);
		}
		
		return this;
	}
}
